import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/generated/l10n.dart';
import 'package:full_display/page/single/single_setting_page.dart';
import 'package:full_display/provide/button_list_provider.dart';
import 'package:full_display/provide/cmd_provider.dart';
import 'package:full_display/routers/route_name.dart';
import 'package:full_display/unit/asset_utils/asset_utils.dart';
import 'package:full_display/unit/navigation/navigation_util.dart';
import 'package:full_display/unit/screen/screen_util.dart';
import 'package:full_display/unit/screen/screen_util1.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:full_display/unit/web_socket/web_sockect_utils.dart';
import 'package:full_display/unit/widgets/drawer/drawer_widget.dart';
import 'package:full_display/unit/widgets/widget_button_list.dart';
import 'package:full_display/unit/widgets/widget_dialog/bluetooth_setting_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/clock_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/widget_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/wifi_setting_dialog.dart';
import 'package:full_display/unit/widgets/widget_media_list.dart';
import 'package:full_display/unit/widgets/widget_switch.dart';
import 'package:image_picker/image_picker.dart';
import 'package:provider/provider.dart';
import 'package:image_picker/image_picker.dart';

class SingleAddPage extends StatefulWidget {
  const SingleAddPage({super.key});

  @override
  State<SingleAddPage> createState() => _SingleAddPageState();
}

class _SingleAddPageState extends State<SingleAddPage> {
  late CMDProvider _cmdData;
  late ButtonListProvider _btnListData;

  @override
  void initState() {
    super.initState();
    // WebSocketUtils()
    //     .sendCustomMessage(52, content: {'value': 23, 'time': getTime()});
  }

  // String getTime() {
  //   String time = '';
  //   DateTime dateTime = DateTime.now();
  //   dateTime.toString().substring(0, 19);
  //   time = '${dateTime.year}'
  //           ' '
  //           '${dateTime.month}'
  //           ' '
  //           '${dateTime.day}'
  //           ' '
  //           '${dateTime.hour}'
  //           ' '
  //           '${dateTime.minute}'
  //           ' '
  //           '${dateTime.second}'
  //           ' ' +
  //       '${dateTime.millisecond}';
  //   return time;
  // }

  @override
  Widget build(BuildContext context) {
    _cmdData = context.watch<CMDProvider>();
    _btnListData = context.watch<ButtonListProvider>();
    print(
        "${ScreenUtil1.screenHeight}====${ScreenUtil1.statusBarHeight}====${ScreenUtil1.bottomBarHeight}");
    return SingleChildScrollView(
      child: Padding(
        padding: EdgeInsets.all(20.0.W),
        child: Center(
          child: Column(
            children: [
              Text(
                _cmdData.deviceID.isNotEmpty ? _cmdData.deviceID : '',
                textAlign: TextAlign.center,
                style: StandardTextStyle.textWhite24BoldStyle,
              ),
              // Container(
              //   height: 30.0.H,
              // ),
              // ButtonListWidget(
              //   btnList: _btnListData.btnList,
              //   tapAction: settingdialog,
              //   isBg: true,
              // ),
              Container(
                height: 10.0.H,
              ),
              SwitchWidget(
                tapAction: switchValue,
                value: _cmdData.deviceSettingInfo.isNotEmpty
                    ? _cmdData.deviceSettingInfo['properties']['open']
                    : false,
              ),
              Container(
                height: 10.0.H,
              ),
              MedisListWidget(
                info: S.of(context).clear_media,
                list: _cmdData.medisList,
                h: 450.0.H,
                clearData: () {
                  showClearAllFileDialog(context);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  switchValue(bool value) {
    // print("------>${value}");
    setState(() {
      _cmdData.deviceSettingInfo['properties']['open'] = value;
    });
    if (value == true) {
      WebSocketUtils().sendMessage(1);
    } else {
      WebSocketUtils().sendMessage(0);
    }
  }

  void showClearAllFileDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
            content: Column(
              children: <Widget>[
                Align(
                  alignment: Alignment(0, 0),
                  child: Text(S.of(context).are_you_delete),
                ),
              ],
            ),
            actions: <Widget>[
              CupertinoDialogAction(
                child: Text(S.of(context).quxiao),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
              CupertinoDialogAction(
                child: Text(S.of(context).queding),
                onPressed: () {
                  Navigator.pop(context);
                  WebSocketUtils().sendCustomMessage(67, content: 0);
                  _cmdData.medisList = [];
                  setState(() {});
                },
              ),
            ],
          );
        });
  }
}
